/* Copyright Thanh-Trung Pham, JAIST, 2013 */

package jp.ac.jaist.input;

import jp.ac.jaist.UsageProfilePartType;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Thanh-Trung Pham
 */
public class RMPLCProbabilityDistributionWrapper {
    private Map<Integer, Double> m_oDistribution;

    /**
     * The constructor.
     * @param lcProbabilityDistribution the loop count probability distribution from the input model.
     */
    public RMPLCProbabilityDistributionWrapper(UsageProfilePartType.LCProbabilityDistribution lcProbabilityDistribution) {
        m_oDistribution = new HashMap<Integer, Double>();
        for(UsageProfilePartType.LCProbabilityDistribution.ForLCValue oForLCValue: lcProbabilityDistribution.getForLCValueArray()){
            int iForLCValue = oForLCValue.getForLCValue();
            double dProb = oForLCValue.getProbability();

            m_oDistribution.put(iForLCValue,dProb);
        }
    }

    /**
     * Get all loop count values.
     * @return all the loop count values.
     */
    public Integer[] getLCValues(){
        return m_oDistribution.keySet().toArray(new Integer[m_oDistribution.size()]);
    }


    /**
     * Get the probability for the loop count value.
     * @param lcValue the loop count value.
     * @return the probability for the loop count value.
     */
    public double getProbability(int lcValue){
        if(!m_oDistribution.containsKey(lcValue)){
            return 0;
        }

        return m_oDistribution.get(lcValue);
    }
}
